package com.sfac.springboot.modules.account.controller;

import com.sfac.springboot.modules.account.service.UserService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * @author jzq
 * @date 2022/8/27 10:38
 */
@SuppressWarnings({"all"})
@Controller
public class AccountController {

    @Autowired
    UserService userService;

    /**
     * localhost/register
     *
     * @param modelMap
     * @return
     */
    @GetMapping(value = "/register")
    public String register(ModelMap modelMap) {
        modelMap.addAttribute("template", "account/register");
        return "index3";
    }


    /**
     * localhost/login
     *
     * @param modelMap
     * @return
     */
    @GetMapping(value = "/login")
    public String login(ModelMap modelMap) {
        modelMap.addAttribute("template", "account/login");
        return "index3";
    }


    /**
     * localhost/logout
     *
     * @return
     */
    @GetMapping("/logout")
    public String logout() {
        userService.logout();
        return "redirect:/login";
    }


    /**
     * localhost/account/users
     *
     * @return
     */
    @GetMapping(value = "/account/users")
    @RequiresRoles(value = {"admin", "manager"}, logical = Logical.OR)
    public String usersPage() {
        return "index";
    }


    /**
     * localhost/account/roles
     *
     * @return
     */
    @GetMapping(value = "/account/roles")
    public String rolesPage() {
        return "index";
    }


    /**
     * localhost/account/resources
     *
     * @return
     */
    @GetMapping(value = "/account/resources")
    public String resourcesPage() {
        return "index";
    }

}
